/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.contact.teacher.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.sys.entity.EmpUser;
import com.jeesite.modules.sys.service.EmpUserService;
import com.jeesite.modules.zx.contact.teacher.entity.TcontactTeacher;
import com.jeesite.modules.zx.contact.teacher.service.TcontactTeacherService;

/**
 * 联系老师Controller
 * @author zpp
 * @version 2020-02-20
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/contact/teacher/tcontactTeacher")
public class TcontactTeacherController extends BaseController {

	@Autowired
	private TcontactTeacherService tcontactTeacherService;
	@Autowired
	private EmpUserService empUserService;
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcontactTeacher get(String id, boolean isNewRecord) {
		return tcontactTeacherService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcontactTeacher tcontactTeacher, Model model) {
		model.addAttribute("tcontactTeacher", tcontactTeacher);
		return "modules/zx/contact/teacher/tcontactTeacherList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcontactTeacher> listData(TcontactTeacher tcontactTeacher, HttpServletRequest request, HttpServletResponse response) {
		tcontactTeacher.setPage(new Page<>(request, response));
		Page<TcontactTeacher> page = tcontactTeacherService.findPage(tcontactTeacher);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:view")
	@RequestMapping(value = "form")
	public String form(TcontactTeacher tcontactTeacher, Model model) {
		EmpUser empUser=new EmpUser();
		empUser.setIdentity("teacher");
		List<EmpUser> teacherList = empUserService.findList(empUser);
		model.addAttribute("teacherList", teacherList);
		model.addAttribute("tcontactTeacher", tcontactTeacher);
		return "modules/zx/contact/teacher/tcontactTeacherForm";
	}

	/**
	 * 保存联系老师
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcontactTeacher tcontactTeacher) {
		tcontactTeacherService.save(tcontactTeacher);
		return renderResult(Global.TRUE, text("保存联系老师成功！"));
	}
	
	/**
	 * 停用联系老师
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcontactTeacher tcontactTeacher) {
		tcontactTeacher.setStatus(TcontactTeacher.STATUS_DISABLE);
		tcontactTeacherService.updateStatus(tcontactTeacher);
		return renderResult(Global.TRUE, text("停用联系老师成功"));
	}
	
	/**
	 * 启用联系老师
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcontactTeacher tcontactTeacher) {
		tcontactTeacher.setStatus(TcontactTeacher.STATUS_NORMAL);
		tcontactTeacherService.updateStatus(tcontactTeacher);
		return renderResult(Global.TRUE, text("启用联系老师成功"));
	}
	
	/**
	 * 删除联系老师
	 */
	@RequiresPermissions("zx:contact:teacher:tcontactTeacher:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcontactTeacher tcontactTeacher) {
		tcontactTeacherService.delete(tcontactTeacher);
		return renderResult(Global.TRUE, text("删除联系老师成功！"));
	}
	
}